﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Net;

namespace WindowsFormsControlLibrary4
{
    public partial class UserControl1 : UserControl
    {
        XmlDocument document = new XmlDocument();
        XmlElement element;
        private String getdate = null;
        private String getyear;
        private String getmonth;
        private String getday;
        public enum batik { Batik_Solo, Batik_Jogja, Batik_Bogor, Batik_Kalimantan, Batik_Pekalongan };
        private batik theme;
        public enum tipe { Daily, Monthly };
        private tipe style;

        private float label1Size;

        private bool CheckConnection(String URL)
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
                request.Timeout = 5000;
                request.Credentials = CredentialCache.DefaultNetworkCredentials;
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                if (response.StatusCode == HttpStatusCode.OK) return true;
                else return false;
            }
            catch
            {
                return false;
            }
        }

        public UserControl1()
        {
            InitializeComponent();
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);

            initDesign();
            if (CheckConnection("http://red-letter.bl.ee/service.php?tipe=get") == true)
            {
                document.Load("http://red-letter.bl.ee/service.php?tipe=get");
                element = document.DocumentElement;
                loadWS();
            }
            else
            {
                MessageBox.Show("Please check your internet connection");
            }
            
            var pos = this.PointToScreen(pictureBox2.Location);
            pictureBox2.Parent = pictureBox1;
            pictureBox2.BackColor = Color.Transparent;
            pictureBox2.Location = pos;
            pos = this.PointToScreen(pictureBox3.Location);
            pictureBox3.Parent = pictureBox1;
            pictureBox3.BackColor = Color.Transparent;
            pictureBox3.Location = pos;

            pos = this.PointToScreen(pictureBox4.Location);
            pictureBox4.Parent = pictureBox1;
            pictureBox4.BackColor = Color.Transparent;
            pictureBox4.Location = pos;

            pos = this.PointToScreen(pictureBox5.Location);
            pictureBox5.Parent = pictureBox1;
            pictureBox5.BackColor = Color.Transparent;
            pictureBox5.Location = pos;

        }
        private void design(Label label) 
        {
            var pos = this.PointToScreen(label.Location);
            pos = pictureBox1.PointToClient(pos);
            label.Parent = pictureBox1;
            label.Location = pos;
            //mengubah background label menjadi transparent
            label.BackColor = System.Drawing.Color.Transparent;
        }
        private void design(Button button)
        {
            var pos = this.PointToScreen(button.Location);
            pos = this.PointToScreen(button.Location);
            pos = pictureBox1.PointToClient(pos);
            button.Parent = pictureBox1;
            button.Location = pos;
            button.BackColor = System.Drawing.Color.Transparent;
        }

        private void initDesign()
        {
            design(label1);
            design(label2);
            design(label3);
            design(label4);
            design(label5);
            design(label6);
            design(label7);
            
            monthCalendar1.Visible = false;
            pictureBox1.BackgroundImage = WindowsFormsControlLibrary4.Properties.Resources.kalender_Batik_solo;
            


            //men-set kalender menjadi tanggal hari ini
            label4.Text = DateTime.Now.ToString("dd");
            label1.Text = transBulan(DateTime.Now.ToString("MMMM"));
            label5.Text = idHari(DateTime.Now.DayOfWeek.ToString());
            label6.Text = " ";
            label7.Text = " ";
         

            //kasih jenis family font
            label1.Font = new Font("Segoe Script", label1.Font.Size, FontStyle.Bold);
            label1.TextAlign = ContentAlignment.MiddleCenter;
            //label4.Font = new Font("Segoe Script", label4.Font.Size);
            label5.Font = new Font("Stencil", label5.Font.Size, FontStyle.Bold);
            label6.Font = new Font("Century Gothic Bold", label6.Font.Size, FontStyle.Bold);
            label7.Font = new Font("Century Gothic Bold", label7.Font.Size, FontStyle.Bold);

            //biar auto center
            label1.Location = new Point(383 / 4 - label1.Width / 2, 100 / 3 - label1.Height / 2);
            label1Size = label1.Font.Size;
            label4.Location = new Point(450 / 4 - label4.Width / 2, 250 * 3 / 6 - (label4.Height / 2));
            label5.Location = new Point(430 / 4 - label5.Width / 2, 230 * 5 / 6 - (label5.Height / 2));
            label6.Location = new Point(450 / 4 - label6.Width / 2, 695 / 3 - label6.Height / 2);
            label7.Location = new Point(440 / 4 - label7.Width / 2, 760 / 3 - label7.Height / 2);

        }

        //untuk mengubah nama bulan (default) menjadi nama bulan (dalam bhs indonesia)
        private string transBulan(String txtBulan)
        {
            string nmBulan = "";
            switch (txtBulan)
            {
                case "January": nmBulan = "JANUARI"; break;
                case "February": nmBulan = "FEBRUARI"; break;
                case "March": nmBulan = "MARET"; break;
                case "April": nmBulan = "APRIL"; break;
                case "May": nmBulan = "MEI"; break;
                case "June": nmBulan = "JUNI"; break;
                case "July": nmBulan = "JULI"; break;
                case "August": nmBulan = "AGUSTUS"; break;
                case "September": nmBulan = "SEPTEMBER"; break;
                case "October": nmBulan = "OKTOBER"; break;
                case "November": nmBulan = "NOVEMBER"; break;
                case "December": nmBulan = "DESEMBER"; break;
            }
            return nmBulan;
        }

        //untuk mengubah nama bulan (dalam bhs indo) ke angka (dalam bentuk string)
        private string bulan(String txtBulan)
        {
            string numBulan = "";
            switch (txtBulan)
            {
                case "JANUARI": numBulan = "01"; break;
                case "FEBRUARI": numBulan = "02"; break;
                case "MARET": numBulan = "03"; break;
                case "APRIL": numBulan = "04"; break;
                case "MEI": numBulan = "05"; break;
                case "JUNI": numBulan = "06"; break;
                case "JULI": numBulan = "07"; break;
                case "AGUSTUS": numBulan = "08"; break;
                case "SEPTEMBER": numBulan = "09"; break;
                case "OKTOBER": numBulan = "10"; break;
                case "NOVEMBER": numBulan = "11"; break;
                case "DESEMBER": numBulan = "12"; break;
            }
            return numBulan;
        }

        //untuk mengubah bulan (dalam bentuk integer) ke dalam nama bulan (dalam bhs indo)
        private string backBulan(int numBulan)
        {
            string txtBulan = "";
            switch (numBulan)
            {
                case 1: txtBulan = "JANUARI"; break;
                case 2: txtBulan = "FEBRUARI"; break;
                case 3: txtBulan = "MARET"; break;
                case 4: txtBulan = "APRIL"; break;
                case 5: txtBulan = "MEI"; break;
                case 6: txtBulan = "JUNI"; break;
                case 7: txtBulan = "JULI"; break;
                case 8: txtBulan = "AGUSTUS"; break;
                case 9: txtBulan = "SEPTEMBER"; break;
                case 10: txtBulan = "OKTOBER"; break;
                case 11: txtBulan = "NOVEMBER"; break;
                case 12: txtBulan = "DESEMBER"; break;
            }
            return txtBulan;
        }

        //untuk mengubah hari (default) ke dalam bentuk bahas indonesia
        private string idHari(String hari)
        {
            string nmHari = "";
            switch (hari)
            {
                case "Monday": nmHari = "Senin"; break;
                case "Tuesday": nmHari = "Selasa"; break;
                case "Wednesday": nmHari = "Rabu"; break;
                case "Thursday": nmHari = "Kamis"; break;
                case "Friday": nmHari = "Jumat"; break;
                case "Saturday": nmHari = "Sabtu"; break;
                case "Sunday": nmHari = "Minggu"; break;
            }
            return nmHari;
        }


        //untuk mencocokkan kalender dengan data XML
        private void loadWS()
        {
            try
            {
            string text = "";
            string text1 = "";
            string text2 = "";
            int tanda = 0;
            for (int i = 1; i < 21; i++)
            {
                XmlNodeList nodes = document.DocumentElement.SelectNodes("event[id='" + i + "']/tanggal_libur");
                //untuk mengecek apakah sudah ketemu atau belum, kalo tanda=0 --> belum ketemu
                //kalo tanda==1 --> keluar dr loop
                if (tanda == 0)
                {
                    foreach (XmlNode node in nodes)
                    {
                        text = node.InnerText;
                       
                        //jika tahun-bulan-hari sama
                        if (text.Substring(0, 2) == label3.Text && text.Substring(2, 2) == label2.Text && text.Substring(5, 2) == bulan(label1.Text) && text.Substring(8, 2) == label4.Text)
                        {
                            switch(text.Substring(5, 2) + text.Substring(8, 2))
                            {
                                case "0101": pictureBox1.ImageLocation = "http://red-letter.bl.ee/resource/tahunBaru.jpg"; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; break;
                                case "0114": pictureBox1.ImageLocation = "http://red-letter.bl.ee/resource/mauludNabi.jpg"; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; break;
                                case "0131": pictureBox1.ImageLocation = "http://red-letter.bl.ee/resource/Imlek.jpg"; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; break;
                                case "0331": pictureBox1.ImageLocation = "http://red-letter.bl.ee/resource/Nyepi.jpg"; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; break;
                                case "0418": pictureBox1.ImageLocation = "http://red-letter.bl.ee/resource/jumat agung.jpg"; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; break;
                                case "0501": pictureBox1.ImageLocation = "http://red-letter.bl.ee/resource/Buruh.jpg"; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; break;
                                case "0515": pictureBox1.ImageLocation = "http://red-letter.bl.ee/resource/Waisak.jpg"; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; break;
                                case "0527": pictureBox1.ImageLocation = "http://red-letter.bl.ee/resource/israMiraj.jpg"; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; break;
                                case "0529": pictureBox1.ImageLocation = "http://red-letter.bl.ee/resource/kenaikanYesus.jpg"; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; break;
                                case "0728": pictureBox1.ImageLocation = "http://red-letter.bl.ee/resource/idulFitri.png"; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; break;
                                case "0729": pictureBox1.ImageLocation = "http://red-letter.bl.ee/resource/idulFitri2.jpg"; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; break;
                                case "0817": pictureBox1.ImageLocation = "http://red-letter.bl.ee/resource/kemerdekaan.png"; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; break;
                                case "1005": pictureBox1.ImageLocation = "http://red-letter.bl.ee/resource/idulAdha.jpg"; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; break;
                                case "0325": pictureBox1.ImageLocation = "http://red-letter.bl.ee/resource/tahunBaruIslam.jpg"; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; break;
                                case "1225": pictureBox1.ImageLocation = "http://red-letter.bl.ee/resource/Natal.jpg"; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; break;
                                case "0420": pictureBox1.ImageLocation = "http://red-letter.bl.ee/resource/paskah.jpg"; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; break;
                                
                            }
                            XmlNodeList nodess = document.DocumentElement.SelectNodes("event[id='" + i + "']/deskripsi_event");
                            XmlNodeList nodesss = document.DocumentElement.SelectNodes("event[id='" + i + "']/nama_event");

                            foreach (XmlNode nodee in nodess)
                            {
                                //if(nodee.InnerText == 
                                text1 = nodee.InnerText;
                                label7.Text = nodee.InnerText;

                                //resize label 7
                                if (label7.Width > 171)
                                {
                                    while (label7.Width > 171)
                                    {
                                        label7.Font = new Font(label7.Font.FontFamily, label7.Font.Size - 0.5f);
                                    }
                                }
                                else
                                {
                                    while (label7.Width <= 170)
                                    {
                                        label7.Font = new Font(label7.Font.FontFamily, label7.Font.Size + 0.5f);
                                    }
                                }
                                //resize label 7

                                //auto center label 7
                                label7.Location = new Point(440 / 4 - label7.Width / 2, 760 / 3 - label7.Height / 2);
                            }
                            foreach (XmlNode nodee in nodesss)
                            {

                                text2 = nodee.InnerText;
                                label6.Text = nodee.InnerText;

                                //resize label 6
                                if (label6.Width > 181)
                                {
                                    while (label6.Width > 181)
                                    {
                                        label6.Font = new Font(label6.Font.FontFamily, label6.Font.Size - 0.5f);
                                    }
                                }
                                else
                                {
                                    while (label6.Width <= 180)
                                    {
                                        label6.Font = new Font(label6.Font.FontFamily, label6.Font.Size + 0.5f);
                                    }
                                }
                                //resize label 6

                                //auto center label 6
                                label6.Location = new Point(450 / 4 - label6.Width / 2, 695 / 3 - label6.Height / 2);

                            }
                            //mengubah warna tanggal dan hari menjadi merah
                            label4.ForeColor = System.Drawing.Color.Red;
                            label5.ForeColor = System.Drawing.Color.Red;
                            tanda++;

                        }
                        else
                        {
                            switch (theme.ToString())
                            {
                                case "Batik_Solo": pictureBox1.ImageLocation = null; pictureBox1.BackgroundImage = WindowsFormsControlLibrary4.Properties.Resources.kalender_Batik_solo; break;
                                case "Batik_Jogja": pictureBox1.ImageLocation = null; pictureBox1.BackgroundImage = WindowsFormsControlLibrary4.Properties.Resources.kalender_Batik_rareti; break;
                                case "Batik_Bogor": pictureBox1.ImageLocation = null; pictureBox1.BackgroundImage = WindowsFormsControlLibrary4.Properties.Resources.kalender_Batik_Bogor; break;
                                case "Batik_Kalimantan": pictureBox1.ImageLocation = null; pictureBox1.BackgroundImage = WindowsFormsControlLibrary4.Properties.Resources.kalender_Batik_kalimantan; break;
                                case "Batik_Pekalongan": pictureBox1.ImageLocation = null; pictureBox1.BackgroundImage = WindowsFormsControlLibrary4.Properties.Resources.kalender_Batik_parang_pekalongan; break;
                            
                                
                             }
                            label7.Text = " ";
                            label6.Text = " ";
                            // hari minggu juga diberi warna merah
                            if (label5.Text == "Minggu")
                            {
                                label4.ForeColor = System.Drawing.Color.Red;
                                label5.ForeColor = System.Drawing.Color.Red;
                            }
                            else
                            {
                                label4.ForeColor = System.Drawing.Color.Black;
                                label5.ForeColor = System.Drawing.Color.Black;
                            }

                        }
                        
                    }
                }
            }
            }
            catch (Exception e)
            {
                //MessageBox.Show(e.Message);
            }
        }


        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void UserControl1_Load(object sender, EventArgs e)
        {

        }

        private void label1_Click_1(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label7_Click(object sender, EventArgs e)
        {

        }


        

        
        

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        
        private void resizeLabel1() 
        {
            if (label1.Width > 130)
            {
                while (label1.Width > 140)
                {
                    label1.Font = new Font(label1.Font.FontFamily, label1.Font.Size - 0.5f, label1.Font.Style);
                }
            }
            else
            {
                label1.Font = new Font(label1.Font.FontFamily, label1Size, label1.Font.Style);
            }
            //resize label 1

            getdate = label3.Text + label2.Text + "-" + bulan(label1.Text) + "-" + label4.Text;
            label1.Location = new Point(383 / 4 - label1.Width / 2, 100 / 3 - label1.Height / 2);
            label4.Location = new Point(450 / 4 - label4.Width / 2, 250 * 3 / 6 - (label4.Height / 2));
            label5.Location = new Point(430 / 4 - label5.Width / 2, 230 * 5 / 6 - (label5.Height / 2));

        }

        

        private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
        {
            //MessageBox.Show(monthCalendar1.SelectionRange.Start.ToShortDateString());
            //m/d/y
            string tanggal = monthCalendar1.SelectionRange.Start.ToShortDateString();
            string[] tgls = tanggal.Split('/');
            int month = Convert.ToInt32(tgls[0]);
            label1.Text = backBulan(month);
            int date = Convert.ToInt32(tgls[1]);
            if (date < 10)
            {
                label4.Text = "0" + date.ToString();
            }
            else
            {
                label4.Text = date.ToString();
            }
            string year = tgls[2];
            label3.Text = year.Substring(0, 2);
            label2.Text = year.Substring(2, 2);
            loadWS();
            resizeLabel1();
            //MessageBox.Show(label1.Text + " " + label4.Text + " " + label3.Text + label2.Text + label6.Text);


            
            //MessageBox.Show(tanggal.
            /*if (tanggal.Substring(1, 1) == "/")
            {
                label4.Text = "0" + tanggal.Substring(0, 0);
            }
            else 
            {
                label4.Text = tanggal.Substring(0, 2);
            }*/

            //label4.Text = monthCalendar1.SelectionRange.Start.ToShortDateString().Substring(0, 2);
            //label1.Text = transBulan(DateTime.Now.ToString("MMMM"));
            //label5.Text = idHari(DateTime.Now.DayOfWeek.ToString());
            //label6.Text = " ";
            //label7.Text = " ";
        }


        [Category("Data")]
        [Description("Get date from selected date or current date in daily view")]
        public String GetDate
        {
            get
            {
                getdate = label3.Text + label2.Text + "-" + bulan(label1.Text) + "-" + label4.Text;
                return getdate;
            }
            set
            {
                getdate = value;
                label4.Text = getdate.Substring(8, 2);
                label3.Text = getdate.Substring(0, 2);
                label2.Text = getdate.Substring(2, 2);
                int date = Convert.ToInt32(label4.Text);
                int m = Convert.ToInt32(getdate.Substring(5, 2));
                int month = Convert.ToInt32(m);
                label1.Text = backBulan(month);
                string year0 = label3.Text + label2.Text;
                int year = Convert.ToInt32(year0);
                DateTime dt = new DateTime(year, month, date);
                label5.Text = idHari(dt.DayOfWeek.ToString());
                loadWS();

            }

        }

        [Category("Data")]
        [Description("Get year from selected date or current date in daily view")]
        public String GetYear
        {
            get
            {
                getyear = label3.Text + label2.Text;
                return getyear;
            }

        }

        [Category("Data")]
        [Description("Get month from selected date or current date in daily view")]
        public String GetMonth
        {
            get
            {
                getmonth = label1.Text;
                return getmonth;
            }

        }

        [Category("Data")]
        [Description("Get day from selected date or current date in daily view")]
        public String GetDay
        {
            get
            {
                getday = label5.Text;
                return getday;
            }

        }

        [Category("Appearance")]
        [Description("Set appearance style of Indonesian Red-Letter Day Calendar")]
        public tipe Style
        {
            get
            {
                return style;
            }
            set
            {
                style = value;
                if (style.ToString() == "Daily")
                {
                    monthCalendar1.Visible = false;
                    label1.Visible = true;
                    label2.Visible = true;
                    label3.Visible = true;
                    pictureBox2.Visible = true;
                    pictureBox3.Visible = true;
                }
                else
                {
                    monthCalendar1.Visible = true;
                    label1.Visible = false;
                    label2.Visible = false;
                    label3.Visible = false;
                    pictureBox2.Visible = false;
                    pictureBox3.Visible = false;
                   
                }
            }
        }

        [Category("Appearance")]
        [Description("Set appearance theme of Indonesian Red-Letter Day Calendar with Indonesian Batik")]
        public batik Theme
        {
            get
            {
                return theme;
            }
            set
            {
                theme = value;
                switch (theme.ToString())
                {
                    case "Batik_Solo": pictureBox1.ImageLocation = null; pictureBox1.BackgroundImage = WindowsFormsControlLibrary4.Properties.Resources.kalender_Batik_solo; break;
                    case "Batik_Jogja": pictureBox1.ImageLocation = null; pictureBox1.BackgroundImage = WindowsFormsControlLibrary4.Properties.Resources.kalender_Batik_rareti; break;
                    case "Batik_Bogor": pictureBox1.ImageLocation = null; pictureBox1.BackgroundImage = WindowsFormsControlLibrary4.Properties.Resources.kalender_Batik_Bogor; break;
                    case "Batik_Kalimantan": pictureBox1.ImageLocation = null; pictureBox1.BackgroundImage = WindowsFormsControlLibrary4.Properties.Resources.kalender_Batik_kalimantan; break;
                    case "Batik_Pekalongan": pictureBox1.ImageLocation = null; pictureBox1.BackgroundImage = WindowsFormsControlLibrary4.Properties.Resources.kalender_Batik_parang_pekalongan; break;
                }
            }
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            // mengubah tanggal ke dalam bentuk integer
            int date = Convert.ToInt32(label4.Text);
            // mengubah bulan ke bentuk angka tapi string
            string m = bulan(label1.Text);
            //mengubah angka bulan menjadi integer
            int month = Convert.ToInt32(m);
            //menggabungkan 2 label tahun 20 + XX
            string year0 = label3.Text + label2.Text;
            //mengubah tahun menjadi integer
            int year = Convert.ToInt32(year0);

            month--;
            if (month < 1)
            {
                month = 12;
                year--;
            }
            if (month == 2)
            {
                if (year % 4 == 0 && date > 29)
                {
                    date = 29;
                }
                else if (date > 28)
                {
                    date = 28;
                }
            }
            if (((month < 8 && month % 2 == 0) || (month >= 8 && month % 2 == 1)) && date > 30)
            {
                date = 30;

            }

            if (date < 10)
            {
                label4.Text = "0" + date.ToString();
            }
            else
            {
                label4.Text = date.ToString();
            }
            DateTime dt = new DateTime(year, month, date);
            label5.Text = idHari(dt.DayOfWeek.ToString());
            label1.Text = backBulan(month);
            string year1 = year.ToString();
            label3.Text = year1.Substring(0, 2);
            label2.Text = year1.Substring(2, 2);
            loadWS();
            resizeLabel1();

        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            // mengubah tanggal ke dalam bentuk integer
            int date = Convert.ToInt32(label4.Text);
            // mengubah bulan ke bentuk angka tapi string
            string m = bulan(label1.Text);
            //mengubah angka bulan menjadi integer
            int month = Convert.ToInt32(m);
            //menggabungkan 2 label tahun 20 + XX
            string year0 = label3.Text + label2.Text;
            //mengubah tahun menjadi integer
            int year = Convert.ToInt32(year0);

            month++;
            if (month > 12)
            {
                month = 1;
                year++;
            }
            if (month == 2)
            {
                if (year % 4 == 0 && date > 29)
                {
                    date = 29;
                }
                else if (date > 28)
                {
                    date = 28;
                }
            }
            if (((month < 8 && month % 2 == 0) || (month >= 8 && month % 2 == 1)) && date > 30)
            {
                date = 30;

            }

            if (date < 10)
            {
                label4.Text = "0" + date.ToString();
            }
            else
            {
                label4.Text = date.ToString();
            }
            DateTime dt = new DateTime(year, month, date);
            label5.Text = idHari(dt.DayOfWeek.ToString());
            label1.Text = backBulan(month);
            string year1 = year.ToString();
            label3.Text = year1.Substring(0, 2);
            label2.Text = year1.Substring(2, 2);
            loadWS();
            resizeLabel1();

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox4_Click(object sender, EventArgs e)
        {
            // mengubah tanggal ke dalam bentuk integer
            int date = Convert.ToInt32(label4.Text);
            // mengubah bulan ke bentuk angka tapi string
            string m = bulan(label1.Text);
            //mengubah angka bulan menjadi integer
            int month = Convert.ToInt32(m);
            //menggabungkan 2 label tahun 20 + XX
            string year0 = label3.Text + label2.Text;
            //mengubah tahun menjadi integer
            int year = Convert.ToInt32(year0);

            date--;
            if (date < 1)
            {
                month--;
                if (month < 1)
                {
                    month = 12;
                    year--;
                }
                if (month == 2)
                {
                    if (year % 4 == 0)
                    {
                        date = 29;
                    }
                    else
                    {
                        date = 28;
                    }
                }
                else if ((month < 8 && month % 2 == 1) || (month >= 8 && month % 2 == 0))
                {
                    date = 31;
                }
                else
                {
                    date = 30;
                }
            }
            if (date < 10)
            {
                label4.Text = "0" + date.ToString();
            }
            else
            {
                label4.Text = date.ToString();
            }
            DateTime dt = new DateTime(year, month, date);
            label5.Text = idHari(dt.DayOfWeek.ToString());
            label1.Text = backBulan(month);
            string year1 = year.ToString();
            label3.Text = year1.Substring(0, 2);
            label2.Text = year1.Substring(2, 2);
            loadWS();


            //resize label 1
            resizeLabel1();
        }

        private void pictureBox5_Click(object sender, EventArgs e)
        {
            int date = Convert.ToInt32(label4.Text);
            string m = bulan(label1.Text);
            int month = Convert.ToInt32(m);
            string year0 = label3.Text + label2.Text;
            int year = Convert.ToInt32(year0);

            date++;
            if (month == 2 && date > 28)
            {
                date = 1;
                month++;
            }
            else if (((month < 8 && month % 2 == 1) || (month >= 8 && month % 2 == 0)) && date > 31)
            {
                date = 1;
                month++;
            }
            else if (((month < 8 && month % 2 == 0) || (month >= 8 && month % 2 == 1)) && date > 30)
            {
                date = 1;
                month++;
            }
            if (month > 12)
            {
                month = 1;
                year++;
            }
            if (date < 10)
            {
                label4.Text = "0" + date.ToString();
            }
            else
            {
                label4.Text = date.ToString();
            }
            DateTime dt = new DateTime(year, month, date);
            label5.Text = idHari(dt.DayOfWeek.ToString());
            label1.Text = backBulan(month);
            string year1 = year.ToString();
            label3.Text = year1.Substring(0, 2);
            label2.Text = year1.Substring(2, 2);
            loadWS();

            //resize label 1
            resizeLabel1();
        }


    }
}
